/*
  Copyright (c) 2008 Arnaud Fabre <arnaud333@gmail.com>
  Copyright (c) 2008 Pierre "delroth" Bourdon <root@delroth.is-a-geek.org>

  This file is part of Vos Tutos Offline.

  Vos Tutos Offline is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  Vos Tutos Offline is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with Vos Tutos Offline.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "mainwindow.h"

#include "alert.h"
#include "latexconfig.h"

#include <QSettings>

#include <QtDebug>

/* Main Window */

VTOMainWindow::VTOMainWindow(QWidget* parent) :
QMainWindow(parent), tutorial(NULL), tutotreeDock(NULL)
{
    initWidgets();
}

VTOMainWindow::~VTOMainWindow()
{
    if(tutorial != NULL)
	delete tutorial;
}

void VTOMainWindow::initWidgets()
{
    setWindowTitle(tr("Vos Tutos Offline"));
    tutotreeDock = new QDockWidget(tr("Tuto tree"));
    addDockWidget(Qt::LeftDockWidgetArea, tutotreeDock);

    nForm = new NForm(this);
    nForm->setEnabled(false);
    
    vtoMenuBar = new VTOMenuBar(this);
    setMenuBar(vtoMenuBar);
    
    statusBar = new QStatusBar(this);
    setStatusBar(statusBar);

    initToolBar();
		
    setCentralWidget(nForm);
    clearLayout();
    readSettings();
}



NForm* VTOMainWindow::getNForm()
{
    return nForm;
}

VTOMenuBar* VTOMainWindow::getMenuBar()
{
    return vtoMenuBar;
}

void VTOMainWindow::latexconfig()
{
	LatexConfigDialog *lcd = new LatexConfigDialog(this);
	lcd->exec();
	
	delete lcd;
}

void VTOMainWindow::readSettings()
{
	QSettings settings("VTO", "Vos Tutos Offline");
	QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
	QSize size = settings.value("size", QSize(400, 400)).toSize();
	resize(size);
	move(pos);
}

void VTOMainWindow::writeSettings()
{
	QSettings settings("VTO", "Vos Tutos Offline");
	settings.setValue("pos", pos());
	settings.setValue("size", size());
}

/* Nform slots */

void VTOMainWindow::licenceChange(int l)
{
    tutorial->setLicence(l);
}

void VTOMainWindow::progressChange(int p)
{
    docSelected->setProgress( (p/5) * 5 );
}

void VTOMainWindow::difficultChange(int d)
{
    docSelected->setDifficult(d);
}

void VTOMainWindow::titleChange(QString t)
{
    docSelected->setTitle(t);
    tutotree->refresh();
}
